package xzy.Controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import xzy.dao.StudentMapper;
import xzy.dao.StudentMesMapper;
import xzy.pojo.Student;
import xzy.pojo.Teacher;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "findStudentPwd_Servlet")
public class findStudentPwd_Servlet extends HttpServlet {
    private static ApplicationContext context=new ClassPathXmlApplicationContext("application.xml");
    StudentMapper studentMapper= (StudentMapper) context.getBean("studentMapper");
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("进入学生账号找回页面");
        request.setCharacterEncoding("utf-8");
        HttpSession session=request.getSession();
        String userName=request.getParameter("userName");
        try{
            Student student=new Student();
            student=studentMapper.findStudentByName(userName);
            if(student!=null){
                session.setAttribute("findStudentName",student.getUserName());
                session.setAttribute("findStudentPwd",student.getPassword());
            }else {
                request.setAttribute("findStudentPwd_error","系统并不存在此学生");
            }
        }catch (Exception e){
            request.setAttribute("findStudentPwd_error","系统并不存在此学生");

        }finally {
            request.getRequestDispatcher("/toFindStudentPwd.jsp").
                    forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
